<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="编号" prop="gdfCode">
        <el-input
          v-model="queryParams.gdfCode"
          placeholder="请输入编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房源城市" prop="gdfCity">
        <el-input
          v-model="queryParams.gdfCity"
          placeholder="请输入房源城市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客服人员" prop="gdfKf">
        <el-input
          v-model="queryParams.gdfKf"
          placeholder="请输入客服人员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房屋户型" prop="gdfFwhx">
        <el-input
          v-model="queryParams.gdfFwhx"
          placeholder="请输入房屋户型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="归属销区" prop="gdfXq">
        <el-input
          v-model="queryParams.gdfXq"
          placeholder="请输入归属销区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="gdfXmName">
        <el-input
          v-model="queryParams.gdfXmName"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房屋性质" prop="gdfFwxz">
        <el-input
          v-model="queryParams.gdfFwxz"
          placeholder="请输入房屋性质"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房源地址" prop="gdfFwdz">
        <el-input
          v-model="queryParams.gdfFwdz"
          placeholder="请输入房源地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房号" prop="gdfNo">
        <el-input
          v-model="queryParams.gdfNo"
          placeholder="请输入房号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房屋全款单价" prop="gdfQkdj">
        <el-input
          v-model="queryParams.gdfQkdj"
          placeholder="请输入房屋全款单价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已售" prop="gdfSfys">
        <el-select v-model="queryParams.gdfSfys" placeholder="请选择是否已售" clearable size="small">
          <el-option
            v-for="dict in gdfSfysOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否展示" prop="gdfIsShow">
        <el-select v-model="queryParams.gdfIsShow" placeholder="请选择是否展示" clearable size="small">
          <el-option
            v-for="dict in gdfIsShowOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['gdf:gdfinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['gdf:gdfinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['gdf:gdfinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['gdf:gdfinfo:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-upload"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" border stripe :data="gdfinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="唯一ID" align="center" prop="id" /> -->
      <el-table-column label="编号" align="center" prop="gdfCode" />
      <el-table-column label="房源城市" align="center" prop="gdfCity" />
      <el-table-column label="归属销区" align="center" prop="gdfXq" />
      <el-table-column label="客服人员" align="center" prop="gdfKf" width="110"/>
      <!-- <el-table-column label="客服链接" align="center" prop="gdfKfUrl" /> -->
      <el-table-column label="项目名称" align="center" width="155" prop="gdfXmName" />
      <el-table-column label="房号" align="center" prop="gdfNo" width="110"/>
      <el-table-column label="房屋户型" align="center" prop="gdfFwhx" width="110"/>
      <el-table-column label="房屋性质" align="center" prop="gdfFwxz" />
      <el-table-column label="建筑面积" align="center" prop="gdfJzmj" />
      <el-table-column label="是否已售" align="center" prop="gdfSfys" :formatter="gdfSfysFormat" />
      <el-table-column label="数量" align="center" prop="gdfCount" />
      <el-table-column label="房源地址" align="center" prop="gdfFwdz" width="160"/>
      <el-table-column label="抵房单价" align="center" prop="gdfDfdj" />
      <el-table-column label="工抵金额" align="center" prop="gdfGdje" />
      <el-table-column label="市场调研价格" align="center" prop="gdfScdyjj" />
      <el-table-column label="房屋全款单价" align="center" prop="gdfQkdj" />
      <el-table-column label="全款总价" align="center" prop="gdfQkzj" />
      <!-- <el-table-column label="三年付每年费用" align="center" prop="gdfSnfmnfy" />
      <el-table-column label="贷款额度" align="center" prop="gdfDked" />
      <el-table-column label="3年预计利息收入" align="center" prop="gdfSnlx" />
      <el-table-column label="三年分期后房屋总价" align="center" prop="gdfSnfqzj" />
      <el-table-column label="三年分期后房屋单价" align="center" prop="gdfSnfqdj" />
      <el-table-column label="房源经度" align="center" prop="gdfJd" />
      <el-table-column label="房源纬度" align="center" prop="gdfWd" />
      <el-table-column label="折价率" align="center" prop="gdfZjl" /> -->
      <el-table-column label="是否展示" align="center" prop="gdfIsShow" :formatter="gdfIsShowFormat" />
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['gdf:gdfinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['gdf:gdfinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工抵房信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!-- <el-form-item label="是否有效" prop="isActive">
          <el-input v-model="form.isActive" placeholder="请输入是否有效" />
        </el-form-item>
        <el-form-item label="租户id" prop="lesseeId">
          <el-input v-model="form.lesseeId" placeholder="请输入租户id" />
        </el-form-item> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="编号" prop="gdfCode">
              <el-input v-model="form.gdfCode" placeholder="请输入房源编号" :disabled="form.id"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="房源城市" prop="gdfCity">
              <el-input v-model="form.gdfCity" placeholder="请输入房源城市" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属销区" prop="gdfXq">
              <el-input v-model="form.gdfXq" placeholder="请输入归属销区" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="gdfXmName">
              <el-input v-model="form.gdfXmName" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="房号" prop="gdfNo">
              <el-input v-model="form.gdfNo" placeholder="请输入房号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客服人员" prop="gdfKf">
              <el-input v-model="form.gdfKf" placeholder="请输入客服人员" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客服链接" prop="gdfKfUrl">
              <el-input v-model="form.gdfKfUrl" placeholder="请输入客服链接" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="房屋户型" prop="gdfFwhx">
              <el-input v-model="form.gdfFwhx" placeholder="请输入房屋户型" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建筑面积" prop="gdfJzmj">
              <el-input v-model="form.gdfJzmj" placeholder="请输入建筑面积" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="房源地址" prop="gdfFwdz">
          <el-input v-model="form.gdfFwdz" placeholder="请输入房源地址" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="房屋性质" prop="gdfFwxz">
              <el-input v-model="form.gdfFwxz" placeholder="请输入房屋性质" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量" prop="gdfCount">
              <el-input v-model="form.gdfCount" placeholder="请输入数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="房源经度" prop="gdfJd">
              <el-input v-model="form.gdfJd" placeholder="请输入房源经度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="房源纬度" prop="gdfWd">
              <el-input v-model="form.gdfWd" placeholder="请输入房源纬度" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否已售">
              <el-select v-model="form.gdfSfys" placeholder="请选择是否已售">
                <el-option
                  v-for="dict in gdfSfysOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否展示">
              <el-select v-model="form.gdfIsShow" placeholder="请选择是否展示">
                <el-option
                  v-for="dict in gdfIsShowOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="抵房单价" prop="gdfDfdj">
              <el-input v-model="form.gdfDfdj" placeholder="请输入抵房单价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工抵金额" prop="gdfGdje">
              <el-input v-model="form.gdfGdje" placeholder="请输入工抵金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="市场调研价格" prop="gdfScdyjj">
              <el-input v-model="form.gdfScdyjj" placeholder="请输入市场调研价格" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="房屋全款单价" prop="gdfQkdj">
              <el-input v-model="form.gdfQkdj" placeholder="请输入房屋全款单价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="全款总价" prop="gdfQkzj">
              <el-input v-model="form.gdfQkzj" placeholder="请输入全款总价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="三年付每年费用" prop="gdfSnfmnfy">
              <el-input v-model="form.gdfSnfmnfy" placeholder="请输入三年付每年费用" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="贷款额度" prop="gdfDked">
              <el-input v-model="form.gdfDked" placeholder="请输入贷款额度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="3年预计利息收入" prop="gdfSnlx">
              <el-input v-model="form.gdfSnlx" placeholder="请输入3年预计利息收入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="三年分期后房屋总价" prop="gdfSnfqzj">
              <el-input v-model="form.gdfSnfqzj" placeholder="请输入三年分期后房屋总价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="三年分期后房屋单价" prop="gdfSnfqdj">
              <el-input v-model="form.gdfSnfqdj" placeholder="请输入三年分期后房屋单价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="折价率" prop="gdfZjl">
          <el-input v-model="form.gdfZjl" placeholder="请输入折价率" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGdfinfo, getGdfinfo, delGdfinfo, addGdfinfo, updateGdfinfo, exportGdfinfo, importTemplate } from "@/api/gdf/gdfinfo";
import { getToken } from "@/utils/auth";
export default {
  name: "Gdfinfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 工抵房信息表格数据
      gdfinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否已售字典
      gdfSfysOptions: [],
      // 是否展示字典
      gdfIsShowOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gdfCode: undefined,
        gdfCity: undefined,
        gdfKf: undefined,
        gdfFwhx: undefined,
        gdfXq: undefined,
        gdfXmName: undefined,
        gdfFwxz: undefined,
        gdfFwdz: undefined,
        gdfNo: undefined,
        gdfQkdj: undefined,
        gdfSfys: undefined,
        gdfIsShow: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/gdf/gdfinfo/importData"
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("is_active").then(response => {
      this.gdfSfysOptions = response.data;
    });
    this.getDicts("is_active").then(response => {
      this.gdfIsShowOptions = response.data;
    });
  },
  methods: {
    /** 查询工抵房信息列表 */
    getList() {
      this.loading = true;
      listGdfinfo(this.queryParams).then(response => {
        this.gdfinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否已售字典翻译
    gdfSfysFormat(row, column) {
      return this.selectDictLabel(this.gdfSfysOptions, row.gdfSfys);
    },
    // 是否展示字典翻译
    gdfIsShowFormat(row, column) {
      return this.selectDictLabel(this.gdfIsShowOptions, row.gdfIsShow);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        isActive: undefined,
        lesseeId: undefined,
        gdfCode: undefined,
        gdfCity: undefined,
        gdfKf: undefined,
        gdfKfUrl: undefined,
        gdfFwhx: undefined,
        gdfXq: undefined,
        gdfXmName: undefined,
        gdfFwxz: undefined,
        gdfFwdz: undefined,
        gdfNo: undefined,
        gdfCount: undefined,
        gdfJzmj: undefined,
        gdfDfdj: undefined,
        gdfGdje: undefined,
        gdfScdyjj: undefined,
        gdfQkdj: undefined,
        gdfQkzj: undefined,
        gdfSnfmnfy: undefined,
        gdfDked: undefined,
        gdfSnlx: undefined,
        gdfSnfqzj: undefined,
        gdfSnfqdj: undefined,
        gdfJd: undefined,
        gdfWd: undefined,
        gdfZjl: undefined,
        gdfSfys: undefined,
        gdfIsShow: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工抵房信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGdfinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工抵房信息";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateGdfinfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addGdfinfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除工抵房信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delGdfinfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有工抵房信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportGdfinfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
